package com.hsgene.generator.constants;

import org.springframework.util.StringUtils;

/**
 * 生成器类型枚举
 *
 * @author wangbing
 * @version 1.0, 2018/6/29
 */
public enum GeneratorEnum {
    /**
     * 短信验证码
     */
    SMS("sms", "短信验证码"),

    USER("user", "用户ID"),

    ORDER("order", "订单编号"),

    ORDER_RECORD("order_record", "订单变更记录编号"),

    APPLY_ORDER("apply_order", "申请单编号"),

    GOODS("goods", "商品编号"),

    PAY("pay", "支付流水号"),

    MATERIAL_APPLY("material_apply", "材料申领编号"),

    MATERIAL_STORAGE("material_storage", "材料入库编号"),

    MATERIAL_UNIT("material_unit", "耗材单位编号"),

    DEFAULT("default", "默认"),

    SHOPING_CAR("shopping_car", "购物车"),

    COMMIT("commit", "评论"),
    HCSQ("HCSQ", "耗材申请规则编号"),
    HCRK("HCRK", "耗材入库编号"),
    BJKX("BJKX", "补寄款记录编号规则"),
    TCBG("TCBG", "基因检测套餐变更记录编号"),
    GTON("GTON", "基因检测申请单编号"),
    MEDI("MEDI", "基因检测订单(医疗类)"),
    GTPF("GTPF", "基因检测订单(商品)"),

    GTRN("GTRN","检测报告编号"),
    UNDEFINED("undefined", "未定义类型");

    /**
     * 类型
     */
    private final String type;

    /**
     * 描述
     */
    private final String desc;

    GeneratorEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    /**
     * 根据type值，确定枚举类型
     * <p>
     * 传入null或""，返回{@code GeneratorEnum.DEFAULT}
     * 传入不存在的类型，返回{@code GeneratorEnum.UNDEFINED}
     * 其它返回相应类型
     * </p>
     *
     * @param type 生成器类型
     * @return 生成器类型枚举
     */
    public static GeneratorEnum getEnum(String type) {
        if (StringUtils.isEmpty(type)) {
            return DEFAULT;
        }
        for (GeneratorEnum generatorEnum : values()) {
            if (generatorEnum.type.equals(type)) {
                return generatorEnum;
            }
        }

        return UNDEFINED;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }
}
